<script setup lang="ts">
import { useCategoryStore } from '@/stores'
import { onMounted, ref } from 'vue'

const categoryStore = useCategoryStore()
onMounted(() => {
  categoryStore.getCategory1()
})
// 一级分类改变触发
const onChange1 = () => {
  categoryStore.option2 = ''
  categoryStore.option3 = ''
  categoryStore.getCategory2(categoryStore.option1 as number)
}
// 二级分类改变触发
const onChange2 = () => {
  categoryStore.option3 = ''
  categoryStore.getCategory3(categoryStore.option2 as number)
}
// 接受父亲信息
defineProps({
  scene: {
    type: Number,
    default: 1
  }
})
</script>

<template>
  <el-card>
    <el-form inline>
      <el-form-item label="一级分类">
        <el-select
          style="width: 240px"
          v-model="categoryStore.option1"
          @change="onChange1"
          :disabled="scene === 1 ? false : true"
        >
          <el-option
            v-for="item in categoryStore.category1List"
            :label="item.name"
            :value="item.id"
            :key="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          style="width: 240px"
          v-model="categoryStore.option2"
          @change="onChange2"
          :disabled="scene === 1 ? false : true"
        >
          <el-option
            v-for="item in categoryStore.category2List"
            :label="item.name"
            :value="item.id"
            :key="item"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select
          style="width: 240px"
          v-model="categoryStore.option3"
          :disabled="scene === 1 ? false : true"
        >
          <el-option
            v-for="item in categoryStore.category3List"
            :label="item.name"
            :value="item.id"
            :key="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>
